package cn.edu.neusoft.wuguangsheng.flowerimpression.fragment;


import android.app.Fragment;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.EmptyRecyclerView;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.ShopAdapter;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.ShopInfoBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.ListListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.GetCollectionShopListModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class ShopShouCShopFragment extends BaseFragment {
    EmptyRecyclerView shoucangshop_rv;
    private List<ShopInfoBean> items;
    boolean up = false;
    private View mEmptyView;
    TextView tv_message;

    @Override
    void initView() {
        shoucangshop_rv = (EmptyRecyclerView) view.findViewById(R.id.shoucangshop_rv);
        mEmptyView = (View)view.findViewById(R.id.id_empty_scshop);
        tv_message = (TextView)view.findViewById(R.id.tv_message);

        GetCollectionShopListModel getCollectionShopListModel = new GetCollectionShopListModel();
        getCollectionShopListModel.getCollectionShopList(getid(),listListener);

    }

    @Override
    void initEvent() {

    }

    @Override
    void initDate() {

    }

    ListListener<ShopInfoBean> listListener = new ListListener<ShopInfoBean>() {
        @Override
        public void onResponse(List<ShopInfoBean> list) {
            LinearLayoutManager linearLayoutManager=new LinearLayoutManager(getContext());
            linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            shoucangshop_rv.setLayoutManager(linearLayoutManager);
            items=list;
            ShopAdapter shopAdapter=new ShopAdapter(getContext(),items,R.layout.shop_item);
            shoucangshop_rv.setAdapter(shopAdapter);
            shoucangshop_rv.setItemAnimator(new DefaultItemAnimator());
            shoucangshop_rv.setEmptyView(mEmptyView);
            tv_message.setText("快去收藏自己喜欢的店铺吧！");
        }

        @Override
        public void onFail(String msg) {

        }
    };

    public ShopShouCShopFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        setLayout_file(R.layout.fragment_shop_shou_cshop);
        return super.onCreateView(inflater,container,savedInstanceState);
    }
    @Override
    public void onPause() {
        super.onPause();
        up = true;
    }

    @Override
    public void onResume() {
        super.onResume();
        if (up) {
            initView();
            initEvent();
            initDate();
            up = false;
        }
    }

}
